package com.wenheng.controller;

import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @Auther: 文恒
 * @Date: 2021/3/17 - 03 - 17 -15:01
 * @Description:com.wenheng.controller
 * @version:1.0
 */
@RestController
public class AuthController {
    @GetMapping("/auth/login")
    public Map<String,Object> login(@RequestParam("userName")String userName, @RequestParam("password")String password){
        Map<String,Object> map = new HashMap<>();
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken= new UsernamePasswordToken(userName,password);
        try{
            subject.login(usernamePasswordToken);
        }catch (UnknownAccountException e1){
            map.put("msg","用户不存在");
            return map;
        }
        map.put("login",SecurityUtils.getSubject().getPrincipal());
        return map;
    }
}
